package com.aaa.shuke2024.service.impl;

import com.aaa.shuke2024.entity.AlarmHistory;
import com.aaa.shuke2024.dao.AlarmHistoryDao;
import com.aaa.shuke2024.service.AlarmHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 历史告警信息(AlarmHistory)表服务实现类
 *
 * @author teacherChen
 * @since 2024-12-04 16:10:58
 */
@Service("alarmHistoryService")
public class AlarmHistoryServiceImpl implements AlarmHistoryService {
    @Resource
    private AlarmHistoryDao alarmHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AlarmHistory queryById(Integer id) {
        return this.alarmHistoryDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param alarmHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AlarmHistory> queryByPage(AlarmHistory alarmHistory, PageRequest pageRequest) {
        long total = this.alarmHistoryDao.count(alarmHistory);
        return new PageImpl<>(this.alarmHistoryDao.queryAllByLimit(alarmHistory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param alarmHistory 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmHistory insert(AlarmHistory alarmHistory) {
        this.alarmHistoryDao.insert(alarmHistory);
        return alarmHistory;
    }

    /**
     * 修改数据
     *
     * @param alarmHistory 实例对象
     * @return 实例对象
     */
    @Override
    public AlarmHistory update(AlarmHistory alarmHistory) {
        this.alarmHistoryDao.update(alarmHistory);
        return this.queryById(alarmHistory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.alarmHistoryDao.deleteById(id) > 0;
    }

    @Override
    public AlarmHistory queryByIp(String serverIp) {
        return alarmHistoryDao.queryByIp(serverIp);
    }
}
